# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None
import sys


class Solution(object):

    def mergeKLists(self, lists):
        """
        :type lists: List[ListNode]
        :rtype: ListNode
        """
        min = sys.maxint
        index = -1
        for i in range(0, len(lists)):
            if lists[i] is None:
                continue
            if lists[i].val < min:
                min = lists[i].val
                index = i
        if index == -1:
            return None
        head = lists[index]
        lists[index] = head.next
        head.next = self.mergeKLists(lists)
        return head
